Skip to content

Comments

Add a fiber-based relay manager#44

Merged
jheysel-r7 merged 7 commits intorapid7:masterfrom
zeroSteiner:feat/io/relay-manager
Dec 2, 2025
Merged

Add a fiber-based relay manager#44
jheysel-r7 merged 7 commits intorapid7:masterfrom
zeroSteiner:feat/io/relay-manager

Conversation

@zeroSteiner
Copy link
Contributor

This adds a fiber-based relay manager and updates the socket abstraction code to use it. From my local and informal testing it propagates events slightly faster. This model though does allow a stream object that needs to relay from more than one source to both use the new #monitor_sock method and do so without creating a thread for each new monitored socket. In the very near future, this will be used by the MsTds::Channel to relay to and from the IO abstraction that handles the TDS framing for SSL necessary to address rapid7/metasploit-framework#18745. I believe we may also be able to use it for services such as the SOCKS proxy to delagate relaying between sockets to the fiber instead of opening a thread per connection. This would offer a performance benefit when many connections are opened and established.

Testing will be the easiest with a pending Metasploit Framework PR which will include the MsTds::Channel object and steps to ensure Meterpreter channels continue to work as necessary. The new close methods for local/remote were necessary to provide hinting to eliminate a deadlock in Meterpreter that would occur when socket was closed from the remote side (the Meterpreter instance sent a close command to Metasploit Framework) and Metasploit would attempt to close it again by sending a frame back to Meterpreter. This isn't necessary because of course Meterpreter already closed it and caused a dead lock where the Meterpreter instance would be unresponsive for about 15 seconds while the request timed out before it'd work just fine again. Now when the local or remote side wants to close the connection, the appropriate methods can be used to only alert the necessary parties on the other side of the relay.

Requires Ruby 3.0+ where non-blocking fibers were added.

@zeroSteiner zeroSteiner marked this pull request as draft October 30, 2025 22:08
@zeroSteiner
Copy link
Contributor Author

zeroSteiner commented Oct 30, 2025

Drafted as I still need to:

  • Write some tests for it
  • Test with the new MsTds::Channel
  • Test with Meterpreter Process channels
  • Test with Meterpreter TCP client sockets
  • Test with Meterpreter TCP server sockets
  • Test with Meterpreter UDP sockets -- The Python Meterpreter seems to have a pre-existing issue with this. More data is present in what is read than what should be there.
  • Test the Metasploit Framework Web Socket client -- There's a pre-existing issue I cataloged here: payload/generic/shell_bind_aws_ssm Fails With a Database metasploit-framework#20675, everything works though when the database isn't connected
  • Test Metasploit Framework double-ssl shells

@zeroSteiner zeroSteiner force-pushed the feat/io/relay-manager branch from 65d936d to e708dde Compare November 5, 2025 21:39
@zeroSteiner zeroSteiner force-pushed the feat/io/relay-manager branch 3 times, most recently from baa30bb to 2221bd5 Compare November 7, 2025 17:34
@zeroSteiner zeroSteiner force-pushed the feat/io/relay-manager branch from d14e6e5 to dce52a0 Compare November 7, 2025 18:45
@zeroSteiner zeroSteiner marked this pull request as ready for review November 7, 2025 18:50
@jheysel-r7 jheysel-r7 merged commit 3f74237 into rapid7:master Dec 2, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants